package com.eddie.interator;

import java.util.Iterator;

/**
 * 在这里Java提供的Iterator就是抽象迭代器，本类是迭代器的实现
 * 实现迭代器定义的方法，例如 hasNext（） next（） remove（），完成集合的迭代
 * @author Eddie
 * @date 2022/08/03 20:32
 **/
public class ComputerCollegeIterator implements Iterator<Object> {

    //这里我们需要Department 是以怎样的方式存放
    private Department[] departments;
    //遍历的位置
    private int position = 0;

    public ComputerCollegeIterator(Department[] departments) {
        this.departments = departments;
    }

    @Override
    public boolean hasNext() {
        return position < departments.length && departments[position] != null;
    }

    @Override
    public Object next() {
        Department department = departments[position];
        position++;
        return department;
    }

    //删除的方法默认空实现
    public void remove() {

    }
}
